package linkedlist.leetcode_24;

public class Solution {
    public ListNode swapPairs(ListNode head) {
        ListNode dummyNode = new ListNode(-1);
        dummyNode.next = head;
        ListNode pre = dummyNode;
        while (pre.next != null && pre.next.next != null) {
            ListNode node1 = pre.next;
            ListNode node2 = pre.next.next;
            pre.next = node2;
            node1.next = node2.next;
            node2.next = node1;
            pre = node1;
        }
        return dummyNode.next;
    }
}
/*
        -1   ->   1   ->   2   ->    3   -> 4
        pre     node1    node2

        -1   ->   2   ->   1   ->    3   -> 4
        pre     node2    node1

        -1   ->   2   ->   1   ->    3   -> 4
                          pre     node1    node2
        -1   ->   2   ->   1   ->    4   -> 3
                          pre     node2    node1
*/
